/*
===============================================================================
 Name        : main.c
 Author      : 
 Version     :
 Copyright   : Copyright (C)
 Description : main definition
===============================================================================
*/

#ifdef __USE_CMSIS
#include "LPC11Uxx.h"
#endif

#include <cr_section_macros.h>
#include <NXP/crp.h>

// Variable to store CRP value in. Will be placed automatically
// by the linker when "Enable Code Read Protect" selected.
// See crp.h header for more information
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;


#include "application.h"
#include "gpio.h"
#include "timer32.h"
#include "DOGSdisplay.h"
#include "ServoCtrl.h"
#include "type.h"
#include "typedefs.h"
#include "num_conversion.h"

// define servo outputs
struct Servo_t servoSpec;

// TODO: insert other definitions and declarations here

int main(void) {
	
	int i;										//, ia;

	initServoCtrl();						// init Servo module
    init_timer32(0, 10);					// init timer32 module for timer 0

/*

	GPIOSetDir(1, 13, 1);					// Servo 1
	GPIOSetDir(1, 14, 1);					// Servo 2
	GPIOSetDir(1, 15, 1);					// Servo 3
	GPIOSetDir(1, 16, 1);					// Servo 3

*/

	initDogs();

	lcd_string(0, 0,  "Hello World",            ptr_font_6x8, DELETE);

	lcd_string(0, 0,  "Teppiche...",            ptr_font_6x8, DELETE);

	// define servo outputs
    servoSpec.port = 1;
    servoSpec.bit = 13;
    servoSpec.used = 1;
    servoSpec.pulseLength = 800;
    setServo(1, servoSpec);						// Servo channel 1 on P1[13]

    servoSpec.port = 1;
    servoSpec.bit = 14;
    servoSpec.used = 1;
    servoSpec.pulseLength = 1200;
    setServo(2, servoSpec);						// Servo channel 2 on P1[14]

    servoSpec.port = 1;
    servoSpec.bit = 15;
    servoSpec.used = 1;
    servoSpec.pulseLength = 1600;
    setServo(3, servoSpec);						// Servo channel 3 on P1[13]

    servoSpec.port = 1;
    servoSpec.bit = 16;
    servoSpec.used = 1;
    servoSpec.pulseLength = 2000;
    setServo(4, servoSpec);						// Servo channel 4 on P1[14]


    servoSpec.bit = 8;
    servoSpec.used = 0;
    servoSpec.pulseLength = 1500;
    setServo(5, servoSpec);						// Servo channel 5 on P1[08]
    servoSpec.bit = 9;
    servoSpec.used = 0;
    servoSpec.pulseLength = 1500;
    setServo(6, servoSpec);						// Servo channel 6 on P1[09]
    servoSpec.bit = 10;
    servoSpec.used = 0;
    servoSpec.pulseLength = 1500;
    setServo(7, servoSpec);						// Servo channel 7 on P1[10]
    servoSpec.bit = 2;
    servoSpec.used = 0;
    servoSpec.pulseLength = 2500;
    setServo(8, servoSpec);						// Servo channel 8 on P1[2]

//	lcd_string(0, 0, "           dlroW olleH", ptr_font_6x8, DELETE);

/*
    while(1)
	{
		lcd_cursor_x = 0;
		lcd_cursor_y = 0;

    	for (ia=0; ia<88; ia++)
		{
			lcd_write_char((ia+33));
			delay32Ms(0,100);
		}
		lcd_clear_all();
	}
*/

    while(1)
    {
		for(i=800;i<2500;i=i+100)
    	{
			servoSpec.port = 1;
			servoSpec.bit = 13;
    		servoSpec.used = 1;
    		servoSpec.pulseLength = i;
    		setServo(1, servoSpec);						// Servo channel 1 on P1[13]

    		lcd_string(0, 0,  "Hello World",            ptr_font_6x8, DELETE);
//    		lcd_string(0, 8,  "0123456789ABCDEF012345", ptr_font_6x8, DELETE);
//    		lcd_string(0, 16, "0123456789ABCDEF012345", ptr_font_6x8, DELETE);
    		lcd_string(0, 24, "0123456789ABCDEF012345", ptr_font_6x8, DELETE);
    		delay32Ms(0,100);
    		lcd_string(0, 0,  "           ",            ptr_font_6x8, DELETE);
       		delay32Ms(0,100);
    	}
    }
//
	return 0 ;
}
